<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="utf-8" />
        <title>chapter8-2</title>
        <link rel="stylesheet" href="/theme/css/main.css" />

        <!--[if IE]>
            <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
</head>

<body id="index" class="home">
        <header id="banner" class="body">
                <h1><a href="/">PythonTutorials </a></h1>
                <nav><ul>
                    <li class="active"><a href="/category/cpp.html">cpp</a></li>
                    <li><a href="/category/python.html">python</a></li>
                </ul>
                </nav>
        </header><!-- /#banner -->
<section id="content" class="body">
  <article>
    <header>
      <h1 class="entry-title">
        <a href="/chapter8-2.html" rel="bookmark"
           title="Permalink to chapter8-2">chapter8-2</a></h1>
    </header>

    <div class="entry-content">
<footer class="post-info">
        <span>Mon 06 April 2020</span>
<span>| tags: <a href="/tag/cpp.html">cpp</a><a href="/tag/progarmming.html">progarmming</a></span>
</footer><!-- /.post-info -->      <h1>说明：</h1>
<ul>
<li>
<p>int fun(int a[10]) 等价于 int fun(int *a) 等价于 int fun(int a[])</p>
</li>
<li>
<p>若数组作为形参，则将数组名做指针变量来处理</p>
</li>
<li>&amp;与*互为逆运算符</li>
<li>*与[] 等价</li>
<li>&amp;与[] 互为逆运算</li>
</ul>
<h1>指向一维数组的指针变量</h1>
<div class="highlight"><pre><span></span><span class="cp">#include</span> <span class="cpf">&lt;stdio.h&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;string.h&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;stdlib.h&gt;</span><span class="cp"></span>
<span class="cp">#define N 5</span>
<span class="kt">void</span> <span class="nf">array</span><span class="p">(</span><span class="kt">int</span> <span class="n">number</span><span class="p">[</span><span class="n">N</span><span class="p">],</span><span class="kt">int</span> <span class="o">*</span><span class="n">p</span><span class="p">);</span>
<span class="kt">void</span> <span class="nf">InputArray</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span><span class="n">p</span><span class="p">,</span><span class="kt">int</span> <span class="n">n</span><span class="p">);</span>
<span class="kt">void</span> <span class="nf">OutputArray</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span><span class="n">p</span><span class="p">,</span><span class="kt">int</span> <span class="n">n</span><span class="p">);</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">n</span><span class="o">=</span><span class="n">N</span><span class="p">,</span><span class="n">number</span><span class="p">[</span><span class="n">N</span><span class="p">];</span>

    <span class="n">InputArray</span><span class="p">(</span><span class="n">number</span><span class="p">,</span><span class="n">n</span><span class="p">);</span>
    <span class="n">OutputArray</span><span class="p">(</span><span class="n">number</span><span class="p">,</span><span class="n">n</span><span class="p">);</span>
        <span class="n">getchar</span><span class="p">();</span>
        <span class="n">getchar</span><span class="p">();</span>
    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
    <span class="p">}</span>

<span class="kt">void</span> <span class="nf">array</span><span class="p">(</span><span class="kt">int</span> <span class="n">number</span><span class="p">[</span><span class="n">N</span><span class="p">],</span><span class="kt">int</span> <span class="o">*</span><span class="n">p</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">for</span><span class="p">(</span><span class="n">p</span><span class="o">=</span><span class="n">number</span><span class="p">;</span><span class="n">p</span><span class="o">&lt;</span><span class="n">number</span><span class="o">+</span><span class="n">N</span><span class="p">;</span><span class="n">p</span><span class="o">++</span><span class="p">)</span>
        <span class="n">scanf</span><span class="p">(</span><span class="s">&quot;%d&quot;</span><span class="p">,</span><span class="n">p</span><span class="p">);</span>

    <span class="k">for</span><span class="p">(</span><span class="n">p</span><span class="o">=</span><span class="n">number</span><span class="p">;</span><span class="n">p</span><span class="o">&lt;</span><span class="n">number</span><span class="o">+</span><span class="n">N</span><span class="p">;</span><span class="n">p</span><span class="o">++</span><span class="p">)</span>
        <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%4d&quot;</span><span class="p">,</span><span class="o">*</span><span class="n">p</span><span class="p">);</span>
<span class="p">}</span>

<span class="kt">void</span> <span class="nf">InputArray</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span><span class="n">p</span><span class="p">,</span><span class="kt">int</span> <span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">i</span><span class="p">;</span>
    <span class="k">for</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
        <span class="n">scanf</span><span class="p">(</span><span class="s">&quot;%d&quot;</span><span class="p">,</span><span class="n">p</span><span class="o">++</span><span class="p">);</span>

<span class="p">}</span>
<span class="kt">void</span> <span class="nf">OutputArray</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span><span class="n">p</span><span class="p">,</span><span class="kt">int</span> <span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
        <span class="kt">int</span> <span class="n">i</span><span class="p">;</span>
    <span class="k">for</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
        <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span><span class="o">*</span><span class="n">p</span><span class="o">++</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>


<p>由于数组和普通变量一样，所以定义指向数组元素的指针变量与定义指向普通变量的指针变量相同
* int s[10],a,b; 
* int c[3][6];
 * int *p; 
* p= &amp;a
* p=&amp;s[2];
* p=&amp;c[2][4]; </p>
<p>(1)在C语言中规定：数组名代表数组的首地址，而且是一个地址常量。
* 如：int a[10],*p;则有如下关系，p=a;等价于p=&amp;a[0];</p>
<blockquote>
<p>(2)当指针变量指向数组中的某一个元素时，指针变量加1后，该指针指向数组中该元素所在位置的的下一个元素，减法类似。
* float a[10];
* float *p; 
* p=&amp;a[4];
* p+1指向a[5];
* p-1指向a[3];</p>
</blockquote>
<p>(3) 已知：int a[N],<em>p=a;
* p+i，a+i，&amp;a[i]，==地址三等价==
* *（p+i）,</em>(a+i),a[i]，p[i]，==元素四等价==
* 注：当指针变量指向数组时，下标运算([])可用于数组也可以用于指针变量名后
* []为下标运算符
1.  *(p+i) <em>(a+i) a[i] p[i]，元素四等价
1.  p++,++p, p+=1, p=p+1  自增四等价
1.  p-- --p p-=1 p=p-1  自减四等价
1.  *p++ *(p++) 先取地址参与</em>运算，然后再地址向下加，即改变了p的指向，以下同理
1.  *p-- <em>(p--)  <br>
1.  *++p 、*(++p) 先地址增加，然后参与</em>运算，以下同理
1.  <em>--p </em>(--p)====</p>
<p>（4）若两个指针变量指向同一个数组，则这两个指针变量可以进行大小的比较：
* char s[10];
* char *p1=s+3,*p2=&amp;s[7];
* 则：
* p1&gt;p2 返回0，假；p1<p2返回1，真
* p1-p2 =>-4
* p2-p1=&gt;4
* 下标小，地址小；下标大，地址大。地址下标做乘除加无意义，可以做减法，得到元素之间间隔得个元素个数（结果要减1）</p>
<p>(5)在形参中，数组实际上是一个指针变量并不是真正的数组，因为该“数组名”是可以改变的，而真正的数组名是不可以改变的</p>
<p>==<strong>(6)若形参是数组或指针变量，则在函数中可以通过该形参改变实参的值</strong>==</p>
<h1>三、指向多维数组的指针变量</h1>
<p>如 int a[3][4];</p>
<ul>
<li>a+1是跳过一行，因为二维数组是行指针，加1是跳过一行，而不是一个元素</li>
<li>切记：</li>
<li><strong>==只有列指针才是真正的指向元素，即指向某一个元素的存储单元==</strong></li>
<li><strong>==一维数组名表示的是列指针；二维数组名表示的是行指针。==</strong></li>
<li>二维数组是行地址，是行指针；一维数组是列地址，是列指针。</li>
<li>如果a是二维数组，则有：<ul>
<li>a是行指针，即指向的是一整行，若对数组名加1，则指向下一行；</li>
<li>*（a+i）和a[i]一样，都是一个列指针，即指向一个元素；</li>
<li>*(a+i)+j和a[i]+j一样，都表示元素a[i][j]的地址，即与&amp;a[i][j]等价*(a+i)+j,a[i]+j</li>
<li></li>
<li>*(<em>(a+i)+j) </em>(a[i]+j) (*(a+i))[j]和a[i][j]一样，都表示元素</li>
</ul>
</li>
<li>
<p>指向多维数组元素的指针变量</p>
<ul>
<li>如：int a[3][4];int *p=&amp;a[0][3];</li>
<li>则：p+1指向元素a[1][0];p+4指向元素a[1][3];p-2指向元素a[0][1];</li>
<li>常用于取二维数组a元素地址的方式：&amp;a[i][j],a[i]+j,*(a+i)+j</li>
<li><strong>==二维数组如果是列指针，则画图是画成多行单列，如果是行指针（int (*r[列数])），则画图画成二维表，然后等价代换，行指针变量换为二维数名==</strong></li>
</ul>
</li>
<li>
<p>指向由m个元素组成的的一维数组的的指针变量（行指针变量）</p>
<ul>
<li>定义 ：类型名 (*指针变量名) [m];其中，m为正整数，m为列数，属于列指针</li>
<li>如：int a[5][7]; int(*p)[7];p = a;</li>
<li>char b[10][80];char (*r)[80];</li>
<li>r=b+5;</li>
<li>普通指针变量：int *p;也叫列指针变量，元素指针变量</li>
</ul>
</li>
</ul>
<h1>三、指向字符串的指针变量</h1>
<p>字符串常量：C语言对字符串常量按照首地址处理字符串常量。
* 第一个字符的地址即为字符串常量的地址。
* 双引号是一字符的地址
* （1） char str[]="china"
* （2） char *p="china";
* （3） str="chinese";
* （4） p="chinese";</p>
<div class="highlight"><pre><span></span># include &lt;stdio.h&gt;
# include &lt;string.h&gt;

int main()
{
char s[20]=&quot;abcdefGHI&quot;;
char *p=&quot;1234567&quot;;
printf(&quot;%s\n&quot;,s+2);
printf(&quot;%s\n&quot;,p+2);
printf(&quot;%s\n&quot;,strcat(s+3,p+4));
printf(&quot;%d\n&quot;,strlen(p+2)); //结束字符\0不加入
printf(&quot;%s\n&quot;,strcpy(s+3,p+9)); //p+9覆盖掉s+3之后的的字符串
printf(&quot;%s\n&quot;,s);
scanf(&quot;%s&quot;,s+3); //输入：ABC DEF,然后回车
printf(&quot;%s&quot;,s);
getchar();
getchar();
return 0;
}
</pre></div>


<h1>五、指向函数的指针变量</h1>
<p>函数名与数组名一样，是起始地址，而且是一个地址常量</p>
<p>定义指向函数的指针变量的格式：
* ==类型名   (*指针变量名)();==
* 1.首地址2.地址常量3.函数地址</p>
<h2>C中的指针定义语句</h2>
<ol>
<li>类型名  (*指针变量名)();</li>
<li>类型名   普通变量名;</li>
<li>类型名   数组名[];</li>
<li>类型名   *指针变量名;</li>
<li>类型名   函数名(){}</li>
<li>类型名   (*指针变量名)[M],行指针。</li>
</ol>
<h3>注意事项：</h3>
<ol>
<li>在定义指向函数的指针变量时，注意有两个小括号必须要有，不需要定义形参；</li>
<li>单独的函数名代表该函数的的首地址（函数的入口地址）；</li>
<li>函数的指针变量只能指向函数的入口处（函数的首地址）；</li>
<li>给指向函数的指针变量赋值时，只写函数名即可，不用带括号和参数
5</li>
</ol>
<h1>六、返回指针的函数（定义返回地址的函数）</h1>
<ol>
<li>
<p>类型名 函数名(形参列表){}</p>
</li>
<li>
<p>返回指针的函数的定义方式为：==类型名  函数名（形参列表）{}==</p>
<ol>
<li>必须要加return</li>
<li>return后面的必须放地址值</li>
<li>变量名=函数调用（和普通函数调用相同）</li>
</ol>
</li>
</ol>
<div class="highlight"><pre><span></span> <span class="nt">int</span> <span class="nt">max</span><span class="o">(</span><span class="nt">int</span> <span class="nt">a</span><span class="o">,</span><span class="nt">int</span> <span class="nt">b</span><span class="o">)</span>
 <span class="p">{</span>
    <span class="err">return</span> <span class="err">a&gt;b?</span><span class="n">a</span><span class="p">:</span><span class="n">b</span><span class="p">;</span>
<span class="p">}</span>

<span class="nt">int</span> <span class="nt">min</span><span class="o">(</span><span class="nt">int</span> <span class="nt">a</span><span class="o">,</span><span class="nt">int</span> <span class="nt">b</span><span class="o">)</span>
<span class="p">{</span>
    <span class="err">return</span> <span class="err">a&gt;b?</span><span class="n">a</span><span class="p">:</span><span class="n">b</span><span class="p">;</span>
    <span class="p">}</span>

<span class="nt">main</span><span class="o">()</span>
<span class="p">{</span>

        <span class="err">int</span> <span class="err">x=6,y=10</span><span class="p">;</span>
    <span class="err">int</span> <span class="err">(*p1)()</span><span class="p">;</span>
    <span class="err">int</span> <span class="err">(*p2)()</span><span class="p">;</span>
    <span class="err">p1=max</span><span class="p">;</span>
    <span class="err">printf(&quot;%d\n&quot;,max(x,y))</span><span class="p">;</span>
    <span class="err">printf(&quot;%d\n&quot;,p1(x,y))</span><span class="p">;</span>
    <span class="err">p2=min</span><span class="p">;</span>
    <span class="err">printf(&quot;%d&quot;,min(x,y))</span><span class="p">;</span>
    <span class="err">printf(&quot;%d&quot;,p2(x,y))</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>


<h1>七、指针数组和指向指针的指针变量</h1>
<ol>
<li>若一个数组的所有元素均为指针类型(地址)，则称为指针数组。</li>
<li>格式：类型名    <em>数组名[常量表达式]；int </em>s[10];</li>
<li>char数组，一个是要画\0,一个是要画单引号。</li>
<li>指向指针的指针变量</li>
<li>用来存放指针变量地址的指针变量，称为指向指针的指针变量</li>
<li>定义格式：类型名 **指针变量名</li>
<li>如：int a=3;int <em>p=&a; int </em><em>q=&p;则</em>q得到变量p（变量a的地址),**k得到变量a的数值(a的值等于3)</li>
</ol>
<div class="highlight"><pre><span></span>int array()
{
    char ch[3][4]={&quot;123&quot;,&quot;456&quot;,&quot;78&quot;},*p[3];
    int i;
    for (i=0;i&lt;3;i++)
        {
            p[i]=ch[i];
            }
    for(i=0;i&lt;3;i++)
        {
            printf(&quot;%s\n&quot;,p[i]);
            }
    return 0;
    }
</pre></div>


<h1>八、空指针</h1>
<ul>
<li>定义 指针变量可以有空值，即指针变量不指向任何变量，不指向任何有用的存储单元。系统中已经将NULL（系统宏名）定义为0，没有对应的内存单元。</li>
<li>int a,b *p=NULL;此时p为空指针，即p不能指向任何有用的存储单元，尽管NULL的数值为0，但是我们不能认为p指向了地址为0的存储单元。</li>
<li>注：（1）当一个指针变量的值为空指针时，我们不能引用他所指向的存储单元；（2）若某指针（地址）的基类为void时，则有引用时应进行相应的强制类型置换。</li>
<li>地址变量定义时应该赋初值（不能任其随机指向）</li>
<li></li>
</ul>
<h1>形参和实参的典型实例（指针和普通变量）</h1>
<div class="highlight"><pre><span></span><span class="cp">#include</span> <span class="cpf">&lt;stdio.h&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;stdlib.h&gt;</span><span class="cp"></span>
<span class="kt">void</span> <span class="nf">Fun</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span><span class="n">par</span><span class="p">);</span>
<span class="kt">void</span> <span class="nf">swap</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span><span class="n">a</span><span class="p">,</span><span class="kt">int</span> <span class="o">*</span><span class="n">b</span><span class="p">);</span>
<span class="kt">void</span> <span class="nf">swap2</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">,</span><span class="kt">int</span> <span class="n">b</span><span class="p">);</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="k">const</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">arg</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">a</span><span class="o">=</span><span class="mi">13</span><span class="p">,</span><span class="n">b</span><span class="o">=</span><span class="mi">14</span><span class="p">;</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;arg = %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span><span class="n">arg</span> <span class="p">);</span>
    <span class="n">Fun</span><span class="p">(</span><span class="o">&amp;</span><span class="n">arg</span><span class="p">);</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;arg = %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span><span class="n">arg</span> <span class="p">);</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;initial:</span><span class="se">\n</span><span class="s">a = %d,b = %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">);</span>
    <span class="n">swap2</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">);</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;has revolked swap2:</span><span class="se">\n</span><span class="s">&quot;</span> <span class="p">);</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;a = %d,b = %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">);</span>
    <span class="n">swap</span><span class="p">(</span><span class="o">&amp;</span><span class="n">a</span><span class="p">,</span><span class="o">&amp;</span><span class="n">b</span><span class="p">);</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;has revokled swap2:</span><span class="se">\n</span><span class="s">&quot;</span> <span class="p">);</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;a = %d,b = %d&quot;</span><span class="p">,</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">);</span>

    <span class="n">getchar</span><span class="p">();</span>
    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>

<span class="kt">void</span> <span class="nf">Fun</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span> <span class="n">par</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;par = %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span><span class="o">*</span><span class="n">par</span> <span class="p">);</span>
    <span class="o">*</span><span class="n">par</span> <span class="o">=</span><span class="mi">2</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">swap</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span><span class="n">a</span><span class="p">,</span><span class="kt">int</span> <span class="o">*</span><span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">temp</span><span class="p">;</span>
    <span class="n">temp</span><span class="o">=*</span><span class="n">a</span><span class="p">;</span>
    <span class="o">*</span><span class="n">a</span><span class="o">=*</span><span class="n">b</span><span class="p">;</span>
    <span class="o">*</span><span class="n">b</span><span class="o">=</span><span class="n">temp</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">swap2</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">,</span><span class="kt">int</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">temp</span><span class="p">;</span>
    <span class="n">temp</span><span class="o">=</span><span class="n">a</span><span class="p">;</span>
    <span class="n">a</span><span class="o">=</span><span class="n">b</span><span class="p">;</span>
    <span class="n">b</span><span class="o">=</span><span class="n">temp</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>


<h1>数组交换两数</h1>
<div class="highlight"><pre><span></span><span class="cp">#include</span> <span class="cpf">&lt;stdio.h&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;stdlib.h&gt;</span><span class="cp"></span>
<span class="kt">void</span> <span class="nf">swap3</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">[]);</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="k">const</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">p</span><span class="p">[]</span><span class="o">=</span><span class="p">{</span><span class="mi">5</span><span class="p">,</span><span class="mi">7</span><span class="p">};</span>
    <span class="n">swap3</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%d, %d&quot;</span><span class="p">,</span><span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">]);</span>
    <span class="n">getchar</span><span class="p">();</span>
    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>

<span class="kt">void</span> <span class="nf">swap3</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">[])</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">temp</span><span class="p">;</span>
    <span class="n">temp</span><span class="o">=</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
    <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
    <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="n">temp</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
    </div><!-- /.entry-content -->

  </article>
</section>
        <section id="extras" class="body">
                <div class="blogroll">
                        <h2>blogroll</h2>
                        <ul>
                            <li><a href="http://getpelican.com/">Pelican</a></li>
                            <li><a href="http://python.org/">Python.org</a></li>
                            <li><a href="http://jinja.pocoo.org/">Jinja2</a></li>
                            <li><a href="#">You can modify those links in your config file</a></li>
                        </ul>
                </div><!-- /.blogroll -->
                <div class="social">
                        <h2>social</h2>
                        <ul>

                            <li><a href="#">You can add links in your config file</a></li>
                            <li><a href="#">Another social link</a></li>
                        </ul>
                </div><!-- /.social -->
        </section><!-- /#extras -->

        <footer id="contentinfo" class="body">
                <p>Powered by <a href="http://www.maxiaoan.com/">Maxiaoan</a></p>
        </footer><!-- /#contentinfo -->

</body>
</html>